﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using MvcAtletIS.Models;

namespace MvcAtletIS.Controllers
{
    public class RegistrationController : Controller
    {
        private atletisEntities db = new atletisEntities();

        // GET: /Registration/
        public ViewResult Index(string ClubsGroupsID)
        {
            if (string.IsNullOrEmpty(ClubsGroupsID))
            {
                ClubsGroupsID = "AZB";
            }

            ViewBag.ClubsGroupsID = new SelectList(db.ClubsGroups.Where(cg => cg.Active == true), "ID", "Name", ClubsGroupsID);
            var clubs = db.Clubs.Where(c => c.Active == true & c.ClubsGroupsID == ClubsGroupsID).OrderBy(c => c.City).ToList();
            
            return View(clubs);
        }

        // GET: /Registration/Competitors/ZTSDU
        [Authorize]
        public ActionResult Competitors(string id)
        {
            var competitors = db.Competitors.Where(c => c.ClubId == id & c.Competitor == true & c.Active == true).OrderBy(c => c.Surname).ToList();
            ViewBag.Clubs = db.Clubs.SingleOrDefault(c => c.ID == id);
            if (ViewBag.Clubs == null)
            {
                return HttpNotFound();
            }
            return View(competitors);
        }

        // GET: /Registration/Coaches/ZTSDU
        [Authorize]
        public ActionResult Coaches(string id)
        {
            var competitors = db.Competitors.Where(c => c.ClubId == id & !string.IsNullOrEmpty(c.CoachClass) & c.Active == true).OrderBy(c => c.Surname).ToList();
            ViewBag.Clubs = db.Clubs.SingleOrDefault(c => c.ID == id);
            if (ViewBag.Clubs == null)
            {
                return HttpNotFound();
            }
            return View(competitors);
        }

        // GET: /Registration/Referees/ZTSDU
        [Authorize]
        public ActionResult Referees(string id)
        {
            var competitors = db.Competitors.Where(c => c.ClubId == id & !string.IsNullOrEmpty(c.RefereeClass) & c.Active == true).OrderBy(c => c.Surname).ToList();
            ViewBag.Clubs = db.Clubs.SingleOrDefault(c => c.ID == id);
            if (ViewBag.Clubs == null)
            {
                return HttpNotFound();
            }
            return View(competitors);
        }

        // GET: /Registration/Contacts/ZTSDU
        [Authorize]
        public ActionResult Contacts(string id)
        {
            var contacts = db.Contacts.Where(c => c.ClubId == id).OrderBy(c => c.Surname).ToList();
            ViewBag.Clubs = db.Clubs.SingleOrDefault(c => c.ID == id);
            if (ViewBag.Clubs == null)
            {
                return HttpNotFound();
            }
            return View(contacts);
        }










    }
}
